package com.bm.controller;

import com.bm.server.Neo4jViewActionServer;
import com.google.gson.Gson;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sx
 * Date: 2022/2/9
 * Time: 20:28
 * Description: java
 */
@RestController
public class Neo4jViewActionController {
    @Resource
    private Neo4jViewActionServer neo4jViewAction;

    @RequestMapping(value = "/search", method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin
    public String getSearch(@RequestParam(name = "string") String string,@RequestParam("jingDu")Integer jingDu){
        if(jingDu==4){
            String allNodes = neo4jViewAction.getAllNodes();
            return allNodes;
        }
        return neo4jViewAction.getsSearching(string.trim(),jingDu);

    }

    @RequestMapping(value = "/getSort", method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin
    public String getSort(){
        List<String> sort = neo4jViewAction.getSort();
        Gson gson = new Gson();
        String s = gson.toJson(sort);
        return s;
    }


    @RequestMapping(value = "/getDisease", method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin
    public String getDisease(){
        List<String> disease = neo4jViewAction.disease();
        Gson gson = new Gson();
        String s = gson.toJson(disease);
        return s;
    }

    @RequestMapping(value = "/getWine", method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin
    public String getWine(){
        List<String> wine = neo4jViewAction.wine();
        Gson gson = new Gson();
        String s = gson.toJson(wine);
        return s;
    }


    @RequestMapping(value = "/getPlaceOrigin", method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin
    public String getPlaceOrigin(){
        List<String> getPlaceOrigin = neo4jViewAction.getPlaceOrigin();
        Gson gson = new Gson();
        String s = gson.toJson(getPlaceOrigin);
        return s;
    }



}
